package com.md.common.dto.page;

import java.io.Serializable;

public class Pagination implements Serializable {

    private static final long serialVersionUID = 2140884608094276850L;
    public static final int DEFAULT_PAGE_SIZE = 10;
    public static final int DEFAULT_CURRENT_SKIP = 1;

    private String keyWords;//查询关键词

    private int pageSize = DEFAULT_PAGE_SIZE; // 每页显示记录数
    private int total; // 总条目数
    private int totalPage; // 总页数
    private int pageNo = DEFAULT_CURRENT_SKIP; // 当前页

    public Pagination() {
    }

    public Pagination(int rows) {
        this(rows, DEFAULT_CURRENT_SKIP);
    }

    public Pagination(int pageSize, int pageNo) {
        this.pageSize = pageSize;
        this.pageNo = pageNo;
    }

    public String getKeyWords() {
        return keyWords;
    }

    public void setKeyWords(String keyWords) {
        this.keyWords = keyWords;
    }


    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
        totalPage = total % pageSize == 0 ? total / pageSize : (total / pageSize + 1);

    }

    public int getPageNo() {
        if (pageNo <= 1) {
            return 1;
        }
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getStart(){
        return pageNo == 0 ? 0 : (pageNo - 1) *  pageSize;
    }

    public Pagination getPagination(){
        Pagination pagination = new Pagination();
        pagination.setPageSize(this.getPageSize());
        pagination.setPageNo(this.getPageNo());
        pagination.setTotal(this.getTotal());
        pagination.setTotalPage(this.getTotalPage());
        return pagination;
    }
}
